const rollup = require("rollup");
// const commonjs = require("rollup-plugin-commonjs");
// const resolve = require("rollup-plugin-node-resolve");
const commonjs = require("@rollup/plugin-commonjs");
const resolve = require("@rollup/plugin-node-resolve");
const { getBabelInputPlugin } = require("@rollup/plugin-babel");
/**
 *
 * @param {Pick<import("rollup").RollupOptions,"input" | "output">} config
 */
async function RollupBuildTool(config) {
  const input = config.input;
  const output = config.output;
  const bundle = await rollup.rollup({
    input,
    resolve: {
      extensions: [".js", ".ts", ".esm.js"],
    },
    plugins: [
      commonjs(),
      resolve(),
      getBabelInputPlugin({
        babelHelpers: "bundled",
        presets: ["@babel/preset-env"],
      }),
    ],
  });
  await bundle.write({ file: output.file, format: "es" });
}

module.exports = RollupBuildTool;
